﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using mmoss.orm;
using System.Windows.Forms;
using mmoss.classes;

namespace mmoss.application.classes
{
    public class cardScan
    {
        private static TextBox tbPointer;
        private static Timer timer1;
        public delegate void CCScannedGood(CCCard l_Card);
        public delegate void CardScannedBad(string l_message);
        public cardScan()
        {
            timer1.Tick += new EventHandler(timer1_Tick);
        }

        void timer1_Tick(object sender, EventArgs e)
        {
            //timer ticked
            timer1.Stop();
            timer1.Enabled = false;
            string sScan = tbPointer.Text;
            MessageBox.Show(sScan);
        }
        public static void ccKeyPress(object sender, KeyEventArgs e)
        {
            tbPointer = ((TextBox)sender);
            if (((TextBox)sender).Text == "") return;
            string sLastChar = ((TextBox)sender).Text.Substring(((TextBox)sender).Text.Length - 1, 1);
            if (timer1.Enabled)
            {
                //keep timer going
                timer1.Stop();
                timer1.Start();
            }
            if (sLastChar == "%")
            {
                //begin TIMER
                timer1.Enabled = true;
                timer1.Start();
            }
            else if (sLastChar == "?")
            {
                //end character -- wait for tic to disable to stop timer and parse
            }
            
        }
    }
}
